/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ddd.service;

import com.ddd.context.Parameters;
import com.ddd.entity.Log;
import com.ddd.util.HibernateUtil;
import com.ddd.util.Util;
import javax.servlet.http.HttpServletRequest;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class LogService extends BaseService {

    private Parameters para;

    public LogService(HttpServletRequest request) {
        para = new Parameters(request);
    }

    public void insert(String journalID, String articleID, String action) {
        IDService ids = new IDService();
        Log log = new Log();

        log.setId(ids.getNextID("log"));
        log.setFkJournalId(journalID);
        log.setFkArticleId(articleID);
        log.setIp(para.getIP());
        log.setAction(action);
        log.setCid(para.getUsername());
        log.setCtime(Util.getTodayWithTime());

        SessionFactory factory = HibernateUtil.getSessionFactory();
        Session session = factory.openSession();
        Transaction tx = session.beginTransaction();
        session.save(log);
        tx.commit();
        session.close();
    }
}
